<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Schedule extends Model
{
    protected $fillable = ['title','project_id','type_id','floor','start_date','end_date','person_id','delaies','file_id','status','region'];

    const POSTONLY = ['title','project_id','type_id','floor','start_date','end_date','person_id','delaies','file_id','status','region'];
    const CONFIG = ['明天待开始'=>'#66D6FF','当天要开始'=>'#FFFF66','按计划实时'=>'#BEE396','明天需完成'=>'#FFB5B5','今日要完成'=>'#F466D4','按计划滞后'=>'#FF6666','未上报状态'=>'#CbC6D4'];

    use HasFactory;

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function project()
    {
        return $this->hasOne(Project::class,'id','project_id')->select('id','title','status');
    }

    public function type()
    {
        return $this->hasOne(ScheduleType::class,'id','type_id')->select('id','title');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','person_id')->select('id','name','role_id')->with('role');
    }

    public function records()
    {
        return $this->hasMany(ScheduleRecord::class,'schedule_id','id')->with('role')->with('user');
    }

    
}
